#include "customwidget.h"
#include "ui_customwidget.h"
#include "adspage.h"

CustomWidget::CustomWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::CustomWidget)
{
    ui->setupUi(this);
    connect(this, &CustomWidget::sendRemoveItem, qobject_cast<Adspage*>(parent), &Adspage::removeItem);
    connect(ui->toolButton, &QPushButton::clicked, this, &CustomWidget::on_toolButton_clicked);
}

CustomWidget::~CustomWidget()
{
    delete ui;
}

void CustomWidget::setText(const QString &type, const QString &rooms, const QString &area, const QString &price, const QString &name, const QString &surname, const QString &patronymic, const QString &phone_number) {
    ui->Type->setText(type);

    if(rooms.toInt() == 0)
        ui->Rooms->hide();
    else
        ui->Rooms->show();
        ui->Rooms->setText(rooms + " Комнат");

    if(area.toInt() == 0)
        ui->Area->hide();
    else
        ui->Area->show();
        ui->Area->setText(area + " Кв. метров");

    ui->Name->setText(name);
    ui->Surname->setText(surname);
    ui->Patronymic->setText(patronymic);
    ui->Number->setText(phone_number);
    ui->Price->setText(price);

}

void CustomWidget::on_toolButton_clicked()
{
   emit sendRemoveItem(ui->Type->text());
}

QString CustomWidget::getText() {
    return ui->Type->text();
}
